package com.app.params.activity

import android.content.Intent
import android.os.Bundle
import android.support.v7.widget.LinearLayoutManager
import com.app.params.App
import com.app.params.HistoryAdapter
import com.app.params.R
import com.app.params.bean.OnlickInterface
import com.app.params.bean.ParamsBean
import common.BaseActivity
import kotlinx.android.synthetic.main.activity_history.*
import sql.ParamsBeanDao

class History : BaseActivity(), OnlickInterface {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_history)
        setTitle_text("历史记录")
        init()
    }

    fun init() {
        var linManager = LinearLayoutManager(this)
        linManager.orientation = LinearLayoutManager.VERTICAL
        hoistyRecyler.layoutManager = linManager
        var app = application as App
        var paramsDao = app.parasmDao
        var list = paramsDao.queryBuilder().orderDesc(ParamsBeanDao.Properties.Time).build().list()
        if (list != null) {
            var adatper = HistoryAdapter(this, list)
            adatper.setOnlickInterface(this)
            hoistyRecyler.adapter = adatper
        }
    }

    override fun getParams(paramsBean: ParamsBean) {
        var intent = Intent()
        intent.putExtra("params", paramsBean)
        setResult(102, intent)
        finish()
    }

}
